package com.huawei.hianalytics.ab.bc.ab;

import com.huawei.hianalytics.ab.bc.ef.ab;
import com.huawei.hms.aaid.constant.AaidIdConstant;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;

public class cd {
    static String ab(String str) {
        try {
            return de.ab(MessageDigest.getInstance(AaidIdConstant.SIGNATURE_SHA256).digest(str.getBytes("UTF-8")));
        } catch (UnsupportedEncodingException e) {
            ab.cd("EncryptUtil", "sha256Digest(): UnsupportedEncodingException: Exception when writing the log file.");
            return "";
        } catch (NoSuchAlgorithmException e2) {
            ab.cd("EncryptUtil", "sha256Digest(): NoSuch Algorithm Exception");
            return "";
        }
    }

    static String ab(char[] cArr, byte[] bArr) {
        try {
            return de.ab(SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1").generateSecret(new PBEKeySpec(cArr, bArr, 10000, DnsConfig.MAX_CACHE_ENTRIES)).getEncoded());
        } catch (InvalidKeySpecException e) {
            ab.de("EncryptUtil", "getAuthToken() encryptPBKDF2 Invalid key specification !");
            return null;
        } catch (NoSuchAlgorithmException e2) {
            ab.de("EncryptUtil", "getAuthToken() encryptPBKDF2 No such algorithm!");
            return null;
        }
    }
}
